[FLINK-39284][table] CREATE OR ALTER MATERIALIZED TABLE doesn't respect schema of existing table#27807
[FLINK-39284][table] CREATE OR ALTER MATERIALIZED TABLE doesn't respect schema of existing table#27807snuyanzin wants to merge 7 commits intoapache:masterfrom
CREATE OR ALTER MATERIALIZED TABLE doesn't respect schema of existing table#27807Conversation
…t constraint changes
… MATERIALIZED TABLE` similar to `CREATE`
…t watermark changes
…t column comment change
| if (!oldColumn.getName().equals(newColumn.getName()) | ||
| || !LogicalTypeCasts.supportsImplicitCast( | ||
| oldColumn.getDataType().getLogicalType(), | ||
| newColumn.getDataType().getLogicalType())) { |
There was a problem hiding this comment.
What happens here if we change we change the type of the column here? From CHAR(1) -> CHAR(4)
| modifyColumnComment.getNewComment() == null | ||
| ? "" | ||
| : modifyColumnComment.getNewComment()); |
There was a problem hiding this comment.
Shouldn't we avoid MODIFY COMMENT if the comment is null, instead of returning:
MODIFY 'id' COMMENT ''There was a problem hiding this comment.
no, this type modification means it is removed
since there is no a dedicated table change for that
There was a problem hiding this comment.
Thanks for the new test setup. I noticed that some cases are not tests:
- Adding a constraint, for the case that
oldConstraint == null - Unchanged table (zero chagnes)
- It would be interesting to have a test that has a schema with only watermark/constraint, no regular columns
There was a problem hiding this comment.
It would be interesting to have a test that has a schema with only watermark/constraint, no regular columns
what do you mean by that?
if there is no explicit columns in schema they will be derived from query and there are already such tests here
There was a problem hiding this comment.
If other tests are covering it, I am fine with it. Thanks for the explanation!
AHeise
left a comment
There was a problem hiding this comment.
Thank you very much for all the fixes. Had some minor things.
| assertThat(operation.asSummaryString()) | ||
| .isEqualTo( | ||
| "CREATE OR ALTER MATERIALIZED TABLE builtin.default.mt\n" | ||
| + " DROP CONSTRAINT ct1,\n" |
There was a problem hiding this comment.
These extra space on the first modification look unintended. Can you please double-check?
| || !LogicalTypeCasts.supportsImplicitCast( | ||
| oldColumn.getDataType().getLogicalType(), | ||
| newColumn.getDataType().getLogicalType())) { | ||
| throw new ValidationException( |
There was a problem hiding this comment.
Can we move the exception also to the operation and just issue a TableChange.ModifyPhysicalColumnType?
| + "Column mismatch at position %d: Original column is [%s], but new column is [%s].", | ||
| i + 1, oldColumn, newColumn)); | ||
| } | ||
| if (!Objects.equals(oldColumn.getComment(), newColumn.getComment())) { |
There was a problem hiding this comment.
Since we often treat comment = '' == comment = null, shall we normalize here? Wrap comments in some StringUtil.emptyIfNull.
| " MODIFY %s COMMENT '%s'", | ||
| EncodingUtils.escapeIdentifier(modifyColumnComment.getNewColumn().getName()), | ||
| modifyColumnComment.getNewComment()); | ||
| modifyColumnComment.getNewComment() == null |
There was a problem hiding this comment.
2-3 commits before, we already had some changes to the comment logic. Can you double-check if the commits are correctly cut?
| "CREATE MATERIALIZED TABLE mt1 (\n" | ||
| + " id INT, t TIMESTAMP_LTZ(3),\n" | ||
| + " WATERMARK FOR t as current_timestamp - INTERVAL '5' SECOND" | ||
| + " WATERMARK FOR t as current_timestamp - INTERVAL '5' SECOND\n" |
There was a problem hiding this comment.
This change should probably go into previous commit.
| } | ||
|
|
||
| @Test | ||
| void testCreateOrAlterMaterializedTableWithNewConstraint() |
There was a problem hiding this comment.
Please squash into respective commit.
What is the purpose of the change
A number of cases like
and then
it will ignore watermark (all cases like create/modify/drop)
same for constraint
also similar issue for column comments
Brief change log
converter and tests
Verifying this change
new tests introduced
Does this pull request potentially affect one of the following parts:
@Public(Evolving): ( no)Documentation